#include <iostream>
#include <vector>
#include <string>

using namespace std;

// FIXME: 感觉你写的这个算法不对，你再仔细检查一下算法和处理流程。
//        需要想想怎么把测试数据放在文件里，批量的测试算法的正确性
string longestCommonPrefix2(vector<string> &strs)
{
    if (!strs.size())
        return "";

    string r = strs[0]; //初始化 r
    for (auto s : strs)
    {
        while (s.substr(0, r.size()) != r)
        {
            r = r.substr(0, r.size() - 1);
            if (r == "")
                return "";  
        }
    }

    return r;
}

string longestCommonPrefix1(vector<string> &strs)
{
    if (!strs.size())
        return "";

    char ch;
    string r;

    for (int i = 0;; ++i)
    {
        if (i < strs[0].size())
            ch = strs[0][i];
        else
            return r;

        for (auto &e : strs)
        {
            if (i < e.size() && e[i] == ch) //匹配成功 下一个
                ;
            else
                return r;
        }
        r += ch;
    }
    return r;
}

int main()
{
    int n;
    cin >> n;
    string ary[n];
    vector<string> val;
    for (int i = 0; i < n; i++)
        cin >> ary[i];
    val.assign(ary, ary + 3);

    cout << longestCommonPrefix2(val) << endl;
    return 0;
}
